﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Web;

namespace JXT.PrimaryKey.Batman.Core.WcfService
{
    public static class ServiceEnvironment
    {
        public const string AuthenticationIdHeader = "Authentication-Id";

        public const string AuthenticationKeyHeader = "Authentication-Key";

        //public const string ServiceNamespace = "http://schemas.myshop.com/information/";

        //public const string ModelNamespace = "http://schemas.myshop.com/informaction/XMLSchema";

        /// <summary>
        /// 服务命名空间
        /// </summary>
        public const string ServiceNamespace = "";

        /// <summary>
        /// 模型命名空间
        /// </summary>
        public const string ModelNamespace = "";

#if REST_JSON

        /// <summary>
        /// web请求格式
        /// </summary>
        public const WebMessageFormat WebRequestFormat = WebMessageFormat.Json;

        /// <summary>
        /// web相应格式
        /// </summary>
        public const WebMessageFormat WebResponseFormat = WebMessageFormat.Json;

#else
        /// <summary>
        /// web请求格式
        /// </summary>
        public const WebMessageFormat WebRequestFormat = WebMessageFormat.Xml;

        /// <summary>
        /// web相应格式
        /// </summary>
        public const WebMessageFormat WebResponseFormat = WebMessageFormat.Xml;

#endif

        /// <summary>
        /// 请求内容封装方式
        /// </summary>
        public const WebMessageBodyStyle WebBodyStyle = WebMessageBodyStyle.Bare;

        public static string GetAuthenticationId()
        {
            if (WebOperationContext.Current == null)
                return null;
            return WebOperationContext.Current.IncomingRequest.Headers.Get(ServiceEnvironment.AuthenticationIdHeader);
        }

        public static string GetAuthenticationKey()
        {
            if (WebOperationContext.Current == null)
                return null;
            return WebOperationContext.Current.IncomingRequest.Headers.Get(ServiceEnvironment.AuthenticationKeyHeader);
        }
    }
}
